package com.zjxny.jobs;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import xyz.erupt.core.annotation.EruptHandlerNaming;
import xyz.erupt.job.handler.EruptJobHandler;

/**
 * 每天执行一次
 */
@Slf4j
@Service
@EruptHandlerNaming("更新账号任务状态")
public class UpdateAccountTaskStatusJob implements EruptJobHandler {
	
	@Resource
	JdbcTemplate jdbcTemplate;
	
	@Override
	public String exec(String code, String param) {
		
		String uSql = "update account_info set task_status=1 where is_valid=1";
		int affectNum = jdbcTemplate.update(uSql);
		log.info("UpdateAccountTaskStatusJob.exec affectNum={},sql={}",affectNum,uSql);
		
		
		//更新需要查询违章的数据
		if(StrUtil.isNotBlank(param)) {
			uSql = "update car_info set task_status=1";
		} else {
			uSql = "update car_info join account_info on account_info.id=car_info.account_info_id set car_info.task_status=1 where car_info.zt like '%G%' and account_info.is_valid=1";
		}
		
		affectNum = jdbcTemplate.update(uSql);

		log.info("UpdateCarInfoStatusJob.exec affectNum={},sql={}",affectNum,uSql);
		return "更新成功";
	}
}
